<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib uri='/WEB-INF/tlds/template.tld' prefix='template' %>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
    <title></title>
    <style type="text/css">
        .part
        {
            float:left;
            width: 450px;
            margin: 5px;
            height: auto;
        }
        .right_part
        {
            height: auto;
            width: 350px;
            float: right;
        }
        .left_part
        {
            height: auto;
            width: auto;
            float: left;
            font-family: Arial, Helvetica, sans-serif;
        }
        #header
        {
            text-align: center;
            font-weight: bolder;
            font-family: Arial, Helvetica, sans-serif;
        }
        #text_txt
        {
            height: 170px;
        }
    </style>
</head>
    <div class="part">
        <div id="header" class="part">
            Изменение игры</div>
        <div class="part">
            <div class="left_part">
                Категория:</div>
            <select id="category_txt" name="category_txt" class="right_part">
            <template:get_cat_option_list/>
        	</select>
        </div>
		<div class="part">
            <div class="left_part">
                Цена(руб.):</div>
            <input id="price_txt" type="text" name="price_txt" class="right_part" />
        </div>
        
        <div class="part">
            <div class="left_part">
                Описание:</div>
            <textarea class="right_part" id="dscr_txt" name="dscr_txt"></textarea>
        </div>
        <div class="part">
            <div class="left_part">
                Картинка:</div>
            <input id="img_txt" type="file" name="img_txt" class="right_part" />
        </div>
        <div class="part">
            <div class="left_part">
                Скриншоты:</div>
            <input id="scr1" type="file" name="scr1" class="right_part" />
        </div>
        <div class="part">
            <input id="scr2" type="file" name="scr2" class="right_part" />
        </div>
        <div class="part">
            <input id="scr3" type="file" name="scr3" class="right_part" />
        </div>
        <div class="part">
            <input id="scr4" type="file" name="scr4" class="right_part" />
        </div>
        <div class="part">
            <input id="scr5" type="file" name="scr5" class="right_part" />
        </div>        
        <div class="part">
            <input type="submit" id = "log_btn" value="Изменить игру" onclick="SubmitItemChange();"/> 
        </div>
        </div>
 <script type="text/javascript">
    $(document).ready(function () {
        $("#error").html("");
    });
    function SubmitItemChange() {    	 
		 var url = window.location.toString();
		 url.match(/\?(.+)$/);
		 var params = RegExp.$1;
		 var params = params.split("&");
		 var queryStringList = {};		 
		 for(var i=0;i<params.length;i++)
		 {
		     var tmp = params[i].split("=");
		     queryStringList[tmp[0]] = unescape(tmp[1]);
		 }
		 var gourl="/add_game?change=true&"
		 for(var i in queryStringList)
		     gourl+=i+"="+queryStringList[i]+"&";
		 var txt=document.getElementById("dscr_txt").value;
		 if(txt!=null && txt!="")
		 {
		 	gourl+="text_txt="+txt;
		 	var prc=document.getElementById("price_txt").value;
		 if(prc!=null && prc!="")
		 {
		 	gourl+="&price_txt="+prc;
		 	var ctgr=document.getElementById("category_txt").value;
		 if(prc!=null && prc!="")
		 {
		 	gourl+="&category_txt="+ctgr;		 			 	
		 	$("#error").html("");
		 	$.ajax({
            url: gourl,
            success: OnSuccessSIC,
            error: OnErrorSIC
        	});
        	
        	}
        	else
		 		$("#error").html("Выберите категорию игры!");
        	}
		 else
		 	$("#error").html("Введите цену игры!");
		 }
		 else
		 	$("#error").html("Введите описание игры!");
    }
    function OnSuccessSIC(resp) {
    	if (resp=="success")
    	{
    		$("#error").html("<div style=\"color: #008800\">Изменения приняты!</div>");
    		window.location.reload();
    	}
    	else
    		OnErrorSIC(resp);
    }
    function OnErrorSIC(resp) {
    	$("#error").html("Не удалось применить изменения!");
    }
    </script>
</html>